package org.wattdepot.simulation.dorm;

import org.junit.Test;
import org.wattdepot.simulation.core.Simulation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

/**
 * Tests the basic simulation.
 * 
 * @author BaoHuy Ung, Alan Lee, Edwin Lim, and Anthony Xu.
 */
public class TestDorm {

  /**
   * Tests the accessor and mutator methods in Basic.
   * 
   * @throws Exception If problems occur.
   */
  @Test
  public void testAccessorMutator() throws Exception {
    Simulation testSimulation = new Dorm();
    testSimulation.setBitsForPT(1);
    testSimulation.setEnergy(2);
    testSimulation.setIntBits(3);
    testSimulation.setLimit(4);
    testSimulation.setPT2(5);
    //assertEquals("Checking get and set for ptBits", testSimulation.getBitsForPT(), 
      //Float.floatToIntBits(1));
    assertEquals("Checking get and set for energy", testSimulation.getEnergy(), 2);
    //assertEquals("Checking get and set for bits", testSimulation.getIntBits(), 
      //Float.floatToIntBits(3));
    assertEquals("Checking get and set for limit", testSimulation.getLimit(), 4);
    assertEquals("Checking get and set for pt2Bits", testSimulation.getPT2(), 5);    
  }
  
  /**
   * Tests the ssValid method in Basic.
   * 
   * @throws Exception If problems occur.
   */
  @Test
  public void testIsValid() throws Exception {
    Simulation testSimulation = new Dorm();
    assertEquals("Checking isValid() for true", testSimulation.isValid(), true);    
  }
  
  /**
   * Tests random number generators to ensure the values they generate are within bounds.
   * 
   * @throws Exception If problems occur.
   */
  @Test
  public void testRandomValues() throws Exception {
    boolean randomValueOutOfBounds = false;
    boolean pt1ValueOutOfBounds = false;
    boolean pt2ValueOutOfBounds = false;
    boolean ct1ValueOutOfBounds = false;
    boolean ct2ValueOutOfBounds = false;
    Simulation testSimulation = new Dorm();   
    float testRandomValue = testSimulation.createRandomValue();
    float testPT1Value = testSimulation.createRandomPT1Value();
    int testPT2Value = testSimulation.createRandomPT2Value();
    int testCT1Value = testSimulation.createRandomCT1Value();
    int testCT2Value = testSimulation.createRandomCT2Value();
    if ((testRandomValue < 0) || (testRandomValue > 22000 )) {
      randomValueOutOfBounds = true;
    }
    if ((testPT1Value < 0) || (testPT1Value > 500051)) {
      pt1ValueOutOfBounds = true;
    }
    if ((testPT2Value < 0) || (testPT2Value > 40051)) {
      pt2ValueOutOfBounds = true;
    }
    if ((testCT1Value < 1) || (testCT1Value > 50001)) {
      ct1ValueOutOfBounds = true;
    }
    if ((testCT2Value < 1) || (testCT2Value > 1001)) {
      ct2ValueOutOfBounds = true;
    }
    assertFalse("Random Value is out of bounds.", randomValueOutOfBounds);  
    assertFalse("PT1 value is out of bounds.", pt1ValueOutOfBounds); 
    assertFalse("PT2 value is out of bounds.", pt2ValueOutOfBounds);
    assertFalse("CT1 value is out of bounds.", ct1ValueOutOfBounds); 
    assertFalse("CT2 value is out of bounds.", ct2ValueOutOfBounds);
  }
  
}
